
let sly = window['sly'] = window['sly'] ? window['sly'] : {}
const SDK_NAMES = [
    'ks',//快手
    'qq',
    'tt',
    'wx',
    'qg',//快游戏
    'swan',//百度
    'h5api',//4399
    'AdSDK'//cocos
]
function isNative() {
    return window['PlatformClass'] != undefined || window['native'] != undefined || window['jsb'] != undefined
}
function isDev() {
    for (let index = 0; index < SDK_NAMES.length; index++) {
        const element = SDK_NAMES[index];
        if (window[element]) {
            return false;
        }
    }
    return !isNative();
}

if (isDev()) {
    class Dev {
        constructor() {
            this.env = {
                USER_DATA_PATH: ""
            }
        }
        request(param) {
            let url = param.url
            let data = param.data
            let method = param.method ? param.method : "GET"
            let isOk = false
            console.log('sendHttpRequest  address ', url)
            let xhr = new XMLHttpRequest()
            xhr.timeout = param.timeout
            xhr.ontimeout = function () {
                param.fail('ontimeout')
            }
            xhr.onload = function () {
                console.log('onload xhr.status', xhr.status, 'xhr.readyState ', xhr.readyState)
                if (xhr.status >= 200 && xhr.status < 400) {
                    if (isOk) {
                        return
                    }
                    isOk = true
                    var data = xhr.responseText
                    let temp = { data: data }
                    param.success(temp)
                } else {
                    param.fail('onload error')
                }
            }
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        if (isOk) {
                            return
                        }
                        isOk = true
                        var data = xhr.responseText
                        let temp = { data: data }
                        param.success(temp)
                    } else {
                        param.fail('onload error')
                    }
                }
            }
            xhr.open(method, url, true)
            let innerHeaer = param.header
            if (innerHeaer) {
                for (var key in innerHeaer) {
                    if (innerHeaer[key]) {
                        xhr.setRequestHeader(key, innerHeaer[key])
                    }
                }
            }
            try {
                xhr.send(data)
            } catch (error) {
                param.fail('send error ' + error)
            }
        }

        getSystemInfoSync() {
            return {
                SDKVersion: '1.0.0'
            }

        }
        getFileSystemManager() {
            return null;
        }

        getUpdateManager() {
            return null;
        }

    }
    sly.dev = new Dev();
}
